package work;

import work.config.Constant;
import work.fram.JDBCConnect;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.sql.Statement;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Insert {

    public static void main(String[] args) throws IOException {


        BufferedReader reader = ReaderMaker.create(new File(Constant.work, "插入.sql"));

        if (reader == null) {
            throw new Error("文件不存在");
        }

        Statement statement = JDBCConnect.getStatement();

        if (statement == null) {
            throw new Error("无法获取连接");
        }


        Pattern compile = Pattern.compile("[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+");

        String line;

        int l = 0;

        int start = "INSERT INTO tc_md_personnel (create_time,sysid,sysdataid,remark,gender,idcard,name,org_name,org_code) VALUES(\"2019-11-19 00:00:00\",\"".length();

        int end = "3b9e1a36-379c-4f4a-b1fe-c6dd7c96b1c8".length() + start;
        while ((line = reader.readLine()) != null) {

            l++;
            try {

                Matcher matcher = compile.matcher(line);
                if (matcher.find()) {

                    line = matcher.group();

                    String sql = "update tc_md_personnel set create_time=\"2019-11-22 0:00:00\" where sysid=\"" + line + "\"";

                    System.out.println(sql);
                    statement.execute(sql);
                }

            } catch (Exception e) {
                System.out.println("执行失败:" + l + "行," + line);
            }
        }

        reader.close();

    }

}
